package com.akk.module.avs.service;

import com.akk.module.avs.entity.AvsYbLoanStepExample;
import com.akk.module.avs.entity.AvsYbStep;
import com.akk.module.avs.entity.AvsYbStepExample;
import com.akk.module.avs.mapper.AvsYbLoanStepMapper;
import com.akk.module.avs.mapper.AvsYbStepMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class AvsYbLoanStepService {

    @Autowired
    private AvsYbStepExample stepExample;

    @Autowired
    private AvsYbStepMapper stepMapper;

    @Autowired
    private AvsYbLoanStepExample loanStepExample;

    @Autowired
    private AvsYbLoanStepMapper loanStepMapper;

    public List<AvsYbStep> queryByParams(Map params){
        stepExample.clear();
        AvsYbStepExample.Criteria criteria = stepExample.createCriteria();
        if (params.containsKey("appId"))
            criteria.andAppIdEqualTo(params.get("appId").toString());
        stepExample.setOrderByClause("step_index");
        return stepMapper.selectByExample(stepExample);
    }

    public AvsYbStep queryById(Long stepId){
        return stepMapper.selectByPrimaryKey(stepId);
    }

    public void save(AvsYbStep step){
        stepMapper.insert(step);
    }

    @Transactional
    public void del(Long id){
        loanStepExample.clear();
        loanStepExample.createCriteria().andLoanIdEqualTo(id);
        loanStepMapper.deleteByExample(loanStepExample);
        stepMapper.deleteByPrimaryKey(id);
    }

    public void update(AvsYbStep step){
        stepMapper.updateByPrimaryKey(step);
    }

}
